package com.example.touch_event;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author yaotianxue
 * @description
 * @date 2024/9/29
 */
public class MyViewGroup extends ViewGroup {
    public MyViewGroup(Context context) {
        super(context);
    }

    public MyViewGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MyViewGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        View child = getChildAt(0);
        child.layout(0,0,300,300);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if(ev.getAction() == MotionEvent.ACTION_DOWN){
            Log.d("TOUCH", "222MyViewGroup dispatchTouchEvent分发按下: ");
        }else{
            Log.d("TOUCH", "222MyViewGroup dispatchTouchEvent分发MOVE或UP: ");
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if(ev.getAction() == MotionEvent.ACTION_DOWN){
            Log.d("TOUCH", "333MyViewGroup onInterceptTouchEvent拦截按下: ");
        }else{
            Log.d("TOUCH", "333MyViewGroup onInterceptTouchEvent拦截MOVE或UP: ");
        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            Log.d("TOUCH", "666MyViewGroup onTouchEvent消费按下: ");
        }else{
            Log.d("TOUCH", "666MyViewGroup onTouchEvent消费MOVE或UP: ");
        }
        return super.onTouchEvent(event);
    }
}
